// JavaScript Document

$(document).ready(function() {

  /* HOME ANIMATION */
  function contentRotate(feature) {
    if (doAnimate) {
      feature.fadeOut("fast", function (feature) {
        return function () {
          $(".feature_content div").hide();

          /* HIGHLIGHT RELEVANT CONTROL */
          if ($(this).attr("id") == "feature_one") {
            $(".feature_nav .on").removeClass("on");
            $(".home_one").addClass("on");
          }
          else if ($(this).attr("id") == "feature_two") {
            $(".feature_nav .on").removeClass("on");
            $(".home_two").addClass("on");
          }
          else if ($(this).attr("id") == "feature_three") {
            $(".feature_nav .on").removeClass("on");
            $(".home_three").addClass("on");
          }
		  else if ($(this).attr("id") == "feature_four") {
            $(".feature_nav .on").removeClass("on");
            $(".home_four").addClass("on");
          }
          /* FADE IN NEXT ITEM OR GO BACK TO FIRST */
          feature.fadeIn("fast", function () {
            if ($(this).attr("id") == "feature_four") {
              setTimeout(function () {
                contentRotate($(".feature_content div:first"));
              }, 4000);
            }
            else {
              setTimeout(function () {
                contentRotate($(feature.next()));
              }, 4000);
            }
          });
        };
      }(feature));
    }
  }

  /* HOME FEATURES */
  $(".feature_nav a").hover(function() {
    var current = $(this).attr("title");
    $(".feature_nav .on").removeClass("on");
    $(this).addClass("on");
  });

  var doAnimate = true;

  contentRotate($(".feature_content div:first"));

  $(".home_one").hover(function() {
    $("#feature_one").fadeIn();
    $("#feature_two").hide();
    $("#feature_three").hide();
	$("#feature_four").hide();
    doAnimate = false;
  });
  $(".home_two").hover(function() {
    $("#feature_one").hide();
    $("#feature_two").fadeIn();
    $("#feature_three").hide();
	$("#feature_four").hide();
    doAnimate = false;
  });
  $(".home_three").hover(function() {
    $("#feature_one").hide();
    $("#feature_two").hide();
    $("#feature_three").fadeIn();
	$("#feature_four").hide();
    doAnimate = false;
  });
  $(".home_four").hover(function() {
    $("#feature_one").hide();
    $("#feature_two").hide();
    $("#feature_three").hide();
	$("#feature_four").fadeIn();
    doAnimate = false;
  });

});